package org.obs.aop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.acegisecurity.AcegiSecurityException;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class ExceptionInterceptor implements HandlerExceptionResolver {

	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
		
		Throwable[] throwables = ExceptionUtils.getThrowables(ex);
		for (int i = 0; i < throwables.length; i++) {
			if (throwables[i] instanceof AcegiSecurityException) {
				throw  (RuntimeException)throwables[i];
			}
			
		}
		return null;
	}

}
